package com.oracle.application.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.oracle.application.feign.MemberFeign;
import com.oracle.application.feign.vo.Member;
import com.oracle.application.feign.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 莉丝妲黛
 */
@RestController
@RequestMapping("/member")
@RefreshScope//自动刷新
public class MemberController {

    @Autowired
    private MemberFeign memberFeign;

    @GetMapping("/getAll")
    @HystrixCommand(fallbackMethod = "fallbackListR")
    public R<List<Member>> getAll(){
        return new R<>(200, "success", this.memberFeign.list());
    }

    public R<List<Member>> fallbackListR(){
        return new R<>(201, "服务调用异常，请稍后再试", null);
    }

    @Value("${myconfig.name}")
    private String name;

    @GetMapping("/getName")
    public String getName(){
    return name;
    }

}
